package com.piggy.logi.sys.controller;

import com.piggy.common.core.utils.poi.ExcelUtil;
import com.piggy.common.core.web.controller.BaseController;
import com.piggy.common.core.web.page.TableDataInfo;
import com.piggy.common.log.annotation.LogiLog;
import com.piggy.common.log.enums.BusinessType;
import com.piggy.common.satoken.utils.SecurityUtils;
import com.piggy.logi.sys.bo.LogiAgentPayStatisticsQueryBo;
import com.piggy.logi.sys.bo.LogiReceivableStatisticsQueryBo;
import com.piggy.logi.sys.service.ILogiFinanceStatisticsService;
import com.piggy.logi.sys.vo.LogiAgentPayStatisticsVo;
import com.piggy.logi.sys.vo.LogiReceivableStatisticsVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 财务统计Controller
 *
 * @author fengxy
 * @date 2023/10/17 21:28
 **/
@Api(value = "财务统计控制器", tags = {"财务统计"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/sys/finance/statistics")
public class LogiFinanceStatisticsController extends BaseController {

    private final ILogiFinanceStatisticsService iLogiFinanceStatisticsService;

    /**
     * 应收统计
     */
    @ApiOperation("应收统计")
    //@SaCheckPermission("sys:finance:statistics:receivable")
    @PostMapping("/receivable")
    public TableDataInfo<LogiReceivableStatisticsVo> receivable(@Validated @RequestBody LogiReceivableStatisticsQueryBo bo) {
        bo.setDeptId(SecurityUtils.getDeptId());
        return iLogiFinanceStatisticsService.receivableStatisticsPage(bo);
    }

    /**
     * 应收统计导出
     */
    @ApiOperation("应收统计导出")
//    @SaCheckPermission("@ss.hasPermi('sys:finance:statistics:receivable:export')")
    @LogiLog(title = "财务统计", businessType = BusinessType.EXPORT)
    @PostMapping("/receivable/export")
    public void receivableExport(@Validated @RequestBody LogiReceivableStatisticsQueryBo bo, HttpServletResponse response) throws IOException {
        bo.setDeptId(SecurityUtils.getDeptId());
        List<LogiReceivableStatisticsVo> list = iLogiFinanceStatisticsService.receivableStatisticsList(bo);
        ExcelUtil<LogiReceivableStatisticsVo> util = new ExcelUtil<>(LogiReceivableStatisticsVo.class);
        util.exportExcel(response, list, "应收统计");
    }

    /**
     * 代收货款统计
     */
    @ApiOperation("代收货款统计")
    //@SaCheckPermission("sys:finance:statistics:agentPay")
    @PostMapping("/agentPay")
    public TableDataInfo<LogiAgentPayStatisticsVo> agentPay(@Validated @RequestBody LogiAgentPayStatisticsQueryBo bo) {
        bo.setDeptId(SecurityUtils.getDeptId());
        return iLogiFinanceStatisticsService.agentPayStatisticsPage(bo);
    }

    /**
     * 代收货款统计导出
     */
    @ApiOperation("代收货款统计导出")
//    @SaCheckPermission("@ss.hasPermi('sys:finance:statistics:agentPay:export')")
    @LogiLog(title = "财务统计", businessType = BusinessType.EXPORT)
    @PostMapping("/agentPay/export")
    public void agentPayExport(@Validated @RequestBody LogiAgentPayStatisticsQueryBo bo, HttpServletResponse response) throws IOException {
        bo.setDeptId(SecurityUtils.getDeptId());
        List<LogiAgentPayStatisticsVo> list = iLogiFinanceStatisticsService.agentPayStatisticsList(bo);
        ExcelUtil<LogiAgentPayStatisticsVo> util = new ExcelUtil<>(LogiAgentPayStatisticsVo.class);
        util.exportExcel(response, list, "代收货款统计");
    }
}
